#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main()
{
    //close(0);
    //close(1);
    //int fda = open("log1.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    //int fda = open("log1.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);
    //printf("fda: %d\n", fda);
   
    int fda = open("log1.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    printf("fda: %d\n", fda);
    dup2(fda, 1);
    printf("hahahaha\n");
    fprintf(stdout, "hahahahaha\n");
    
    //close(0);
    //int fda = open("log1.txt", O_RDONLY); // 0
    //printf("fda: %d\n", fda);
    //dup2(fda, 0);
    //char buffer[64];
    //fgets(buffer, sizeof buffer, stdin); // stdin->0
    //printf("%s\n", buffer);

    //close(fda);

    //int fdb = open("log2.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    //printf("fdb: %d\n", fdb);
    //int fdc = open("log3.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);
    //printf("fdc: %d\n", fdc);

    return 0;
}
